//
//  CORSMainViewController.m
//  iCourse
//
//  Created by coco on 12-10-15.
//  Copyright (c) 2012年 1011. All rights reserved.
//

#import "CORSMainViewController.h"
#import "CORSSiderView.h"

@interface CORSMainViewController ()

@end

@implementation CORSMainViewController
@synthesize isShowSiderView = _isShowSiderView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _isShowSiderView = NO;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Flipside View Controller

- (void)flipsideViewControllerDidFinish:(CORSFlipsideViewController *)controller
{
    [self.flipsidePopoverController dismissPopoverAnimated:YES];
    self.flipsidePopoverController = nil;
}

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    self.flipsidePopoverController = nil;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showAlternate"]) {
        [[segue destinationViewController] setDelegate:self];
        UIPopoverController *popoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
        self.flipsidePopoverController = popoverController;
        popoverController.delegate = self;
    }
}

- (void)dealloc
{
    [_managedObjectContext release];
    [_flipsidePopoverController release];
    [_siderView release];
    [super dealloc];
}

- (IBAction)togglePopover:(id)sender
{
    if (self.flipsidePopoverController) {
        [self.flipsidePopoverController dismissPopoverAnimated:YES];
        self.flipsidePopoverController = nil;
    } else {
        [self performSegueWithIdentifier:@"showAlternate" sender:sender];
    }
}

- (IBAction)showSiderView:(id)sender
{
    if (_isShowSiderView == NO)
    {
        [UIView beginAnimations:@"moveIn" context:nil];
        [UIView setAnimationDuration:0.6f];
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        [UIView setAnimationTransition:UIViewAnimationOptionTransitionNone forView:_siderView cache:YES];
        _siderView.frame = CGRectMake(0, 44, 1024, 704);
        [UIView commitAnimations];
        
        _isShowSiderView = YES;
    }
    else
    {
        [UIView beginAnimations:@"moveOut" context:nil];
        [UIView setAnimationDuration:0.4f];
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        [UIView setAnimationTransition:UIViewAnimationOptionTransitionNone forView:_siderView cache:YES];
        _siderView.frame = CGRectMake(-786, 44, 1024, 704);
        [UIView commitAnimations];
        
        _isShowSiderView = NO;
    }
}
@end
